package com.msos.service.SMSQuery;

import com.msos.dao.SMSQueryDao.SMSQueryDao;
import com.msos.model.Message.Message;
import com.msos.model.RespPageBean.RespPageBean;
import com.msos.model.customer.Customer;
import com.msos.utils.CommonsUtils;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName: SMSQueryService
 * @Description: TODO
 * @Author: hsx
 * @Date: 2022/4/13 9:35
 * @Version: v1.0
 */
public class SMSQueryService {
    SMSQueryDao smsQueryDao = new SMSQueryDao();

    public RespPageBean getAllMessage(String mid,Customer customer, String page, String rows, String sort, String order) {
        Long total = null;
        List<Message> list = null;
        try {
            //获取总记录数
            total = smsQueryDao.getTotal(mid);
            int offset = Integer.parseInt(page);
            int size = Integer.parseInt(rows);
            list = smsQueryDao.getAllMessage(mid,customer,(offset - 1) * size, size, sort, order);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new RespPageBean(total,list);
    }

    public Integer deleteMessageByMid(int mid) {
        try {
            return smsQueryDao.deleteMessageByMid(mid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return CommonsUtils.EXCEPTION_ERROR;
    }

    public List<Message> getSendDateBySephone(Customer customer) {
        try {
            return smsQueryDao.getSendDateBySephone(customer);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
